//顶部商品数量
var user = document.querySelectorAll(".main .shang")
var shul = user.length
console.log(shul)
var poi = document.querySelector(".shul")
poi.innerHTML = shul

var zong = document.querySelectorAll(".jia li")
var loi = document.querySelector(".end .endj")
var js = 0
for (var y = 0; y < zong.length; y++) {
    var ji = zong[y].innerHTML
    ji = Number(ji)
    console.log(ji)
    js = js + ji
    console.log(js)
}
js=js.toFixed(2)
loi.innerHTML = js

    //        删除操作
var shanchu = document.querySelectorAll(".shan")
var shop = document.querySelector(".main")
for (var k = 0; k < shanchu.length; k++) {
    shanchu[k].addEventListener('click', function () {
        console.log(this.parentNode.parentNode)
        shop.removeChild(this.parentNode)
            //        顶部商品数量
        var user = document.querySelectorAll(".main .shang")
        var shul = user.length
        console.log(shul)
        var poi = document.querySelector(".shul")
        poi.innerHTML = shul
            //        总价
        var zong = document.querySelectorAll(".zong")
        var loi = document.querySelector(".end .endj")
        var js = 0
        for (var y = 0; y < zong.length; y++) {
            var ji = zong[y].innerHTML
            ji = Number(ji)
            console.log(ji)
            js = js + ji
            console.log(js)
        }
        js=js.toFixed(2)
        loi.innerHTML = js
    })
}

var input = document.querySelectorAll(".lia")
for (var i = 0; i < input.length; i++) {
    input[i].addEventListener('change', function () {
        //        获取单价
        var jis = this.parentNode.parentNode.children[3].firstElementChild.innerHTML
        
        var qk=this.parentNode.parentNode.children[7].innerHTML
        console.log(qk)
            //        获取数量值
        console.log(this.value)
            //        小计
        var po = jis * this.value
        po=po.toFixed(2)
      var aa=  this.parentNode.parentNode.children[5].firstElementChild
      aa.innerHTML=po
      
      var pa=qk*this.value
        pa=pa.toFixed(2)
        console.log(pa)
        this.parentNode.parentNode.children[5].lastElementChild.innerHTML= pa
            //        总价
        var loi = document.querySelector(".end .endj")
        var zong = document.querySelectorAll(".zong")
        var js = 0
        for (var y = 0; y < zong.length; y++) {
            var ji = zong[y].innerHTML
            ji = Number(ji)
//            console.log(ji)
            js = js + ji
//            console.log(js)
        }
        js=js.toFixed(2)
        loi.innerHTML = js
    })
}